//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------

cbuffer neverChanges
{
    matrix view;
};

cbuffer changeOnResize
{
    matrix projection;
};

cbuffer changesEveryFrame
{
    matrix world;
    float4 meshColor;
    float4 lightPos;
};

struct VS_INPUT
{
    float4 pos : POSITION;
};

struct PS_INPUT
{
    float4 pos : SV_POSITION;
    nointerpolation float3 interPos : TEXCOORD1;
};


// Blending

BlendState srcAlphaBlendingAdd
{
	BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = INV_SRC_ALPHA;
    BlendOp = ADD;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT) 0;
    output.pos = mul(input.pos, world);
    output.pos = mul(output.pos, view);
    output.pos = mul(output.pos, projection);
    output.interPos = input.pos.xyz;
    
    return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PS_INPUT input) : SV_Target
{
	float3 pixelToLight = (float3)lightPos - input.interPos;
    float4 finalColor = meshColor/pow(length(pixelToLight),10.0);
    finalColor.a = meshColor.a;
    return finalColor;
    //return meshColor;
}


//--------------------------------------------------------------------------------------
technique10 render
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_0, PS()));
        
        SetBlendState(srcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF);
    }
}


